const {exec} = require("child_process");
let start_flag = false

function startBrowser() {
  if (start_flag) return
  start_flag = !start_flag
  let url = 'http://localhost:3000/'
  switch (process.platform) {
    case "darwin":
      exec(`open ${url}`);
      break
    case "win32":
      exec(`start ${url}`);
      break
  }
}

function getCurrentTime() {
  let date = new Date();//当前时间
  let year = date.getFullYear() //年
  let month = repair(date.getMonth() + 1);//月
  let day = repair(date.getDate());//日
  let hour = repair(date.getHours());//时
  let minute = repair(date.getMinutes());//分
  let second = repair(date.getSeconds());//秒
  //当前时间
  let curTime = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  return curTime;
}

//若是小于10就加个0
function repair(i) {
  if (i >= 0 && i <= 9) return "0" + i;
  else return i;
}

module.exports = {
  startBrowser,
  getCurrentTime
}
